package org.vt.ece4564.pcw.textinclass;

import org.apache.http.cookie.Cookie;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

public class SMSReceiver extends BroadcastReceiver {
	
	private Cookie cookie_;
	
	public SMSReceiver(Cookie cookie) {
		cookie_ = cookie;
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		Bundle pdusBundle = intent.getExtras();
		Object[] pdus = (Object[]) pdusBundle.get("pdus");
		
		SmsMessage messages = SmsMessage.createFromPdu((byte []) pdus[0]);
		
		UploadMessageTask task = new UploadMessageTask(cookie_, messages.getOriginatingAddress(), messages.getMessageBody());
		
		task.execute();
	}

}
